import { reactive, onMounted } from 'vue'
import axios from 'axios'

export default function () {
  let dogList = reactive(['https://images.dog.ceo/breeds/pembroke/n02113023_8021.jpg'])

  async function getLog() {
    try {
      let result = await axios.get('https://dog.ceo/api/breed/pembroke/images/random')
      dogList.push(result.data.message)
    } catch (error) {
      alert(error)
    }
  }

  // 也可以定义系统生命周期钩子函数
  onMounted(() => {
    console.log('onMounted ...')
  })

  // 向外部提供对象
  return { dogList, getLog }
}
